#ifndef PRAXIS_CORE_SCHEMA_SERVICE_H_
#define PRAXIS_CORE_SCHEMA_SERVICE_H_

#include <memory>
#include <string>

#include "praxis/core/backend_stubs.h"

namespace praxis {
/**
 * @class CSchemaService
 * @brief Manages loading and providing access to the master JSON schema.
 *
 * This service ensures that the schema is loaded only once and provides
 * a central, read-only access point for all other modules.
 */
class PRAXIS_API CSchemaService {
 public:
  CSchemaService();
  ~CSchemaService();

  CSchemaService(const CSchemaService&) = delete;
  CSchemaService& operator=(const CSchemaService&) = delete;

  /**
   * @brief Loads the schema from a JSON file.
   * @param filepath The path to the schema file.
   * @throws std::runtime_error if the file cannot be found or parsed.
   */
  void LoadFromFile(const std::string& filepath);

  /**
   * @brief Gets the root of the entire loaded schema.
   * @return A const reference to the root JSON object.
   */
  const json& GetRoot() const;

  /**
   * @brief Gets a specific sub-schema by its top-level key.
   * @param key The key of the desired sub-schema (e.g., "triggers").
   * @return A const reference to the sub-schema JSON object.
   * @throws std::runtime_error if the key is not found.
   */
  const json& GetSubSchema(const std::string& key) const;

 private:
  struct Impl;
  std::unique_ptr<Impl> impl_;
};
}  // namespace praxis

#endif  // PRAXIS_CORE_SCHEMA_SERVICE_H_
